package springboot.test15.servlet;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration(proxyBeanMethods = true)
public class myConfiguration {
    @Bean
    public ServletRegistrationBean myServlet(){
        myServlet ms = new myServlet();
        return new ServletRegistrationBean(ms,"/myServlet","/myServlet1");
    }
    @Bean
    public FilterRegistrationBean myFilter(){
        myFilter mf = new myFilter();
        //只拦截Servlet规定的路径
        // return new FilterRegistrationBean(mf,myServlet());
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(mf);
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/myServlet","/myServlet1"));
        return filterRegistrationBean;
    }
    @Bean
    public ServletListenerRegistrationBean myListener(){
        myListener ml = new myListener();
        return new ServletListenerRegistrationBean(ml);
    }
}
